package generics;

import java.util.Objects;

public class Holder<T> {
	private T value;

	public Holder() {
	}

	public Holder(T val) {
		value = val;
	}

	public void set(T val) {
		value = val;
	}

	public T get() {
		return value;
	}

	@SuppressWarnings("rawtypes")
	@Override
	public boolean equals(Object o) {
		return o instanceof Holder && Objects.equals(value, ((Holder) o).value);
	}

	@Override
	public int hashCode() {
		return Objects.hashCode(value);
	}

	@SuppressWarnings("unused")
	public static void main(String[] args) {
		Holder<Apple> apple = new Holder<>(new Apple());
		Apple d = apple.get();
		apple.set(d);
		Holder<? extends Fruit> fruit = apple;
		Fruit p = fruit.get();
		d = (Apple) fruit.get();
		try {
			Orange c = (Orange) fruit.get();
		} catch (Exception e) {
			System.out.println(e);
		}
		System.out.println(fruit.equals(d));
	}
}